#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <mutex>

#include "../comm/util.hpp"
#include "../comm/log.hpp"
#include "oj_model.hpp"
#include <ctemplate/template.h>


namespace ns_view
{
    using namespace ns_model;

    const std::string template_path = "./template/";
    class View
    {
    public:
        View()
        {}
        ~View()
        {}
    public:
        // 题目编号 题目名称 题目难度 （表格显示）
        void AllExpandHtml(const std::vector<struct Question> &all, std::string *html)
        { 
            // 0. 待渲染网页路径
            const std::string src_html = template_path + "all_questions.html";
            
            // 1. 构建字典序
            ctemplate::TemplateDictionary root("all_questions");;
            for(auto & q : all)
            {
                ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q._number);
                sub->SetValue("title", q._title);
                sub->SetValue("star", q._star);
            }

            //2. 获取被渲染网页
            ctemplate::Template *tp = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);

            //3. 开始渲染
            tp->Expand(html, &root);
        }

        void OneExpandHtml(const struct Question &q,  std::string *html)
        {
            const std::string src_html = template_path + "one_question.html";
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number", q._number);
            root.SetValue("title", q._title);
            root.SetValue("star", q._star);
            root.SetValue("desc", q._desc);
            root.SetValue("pre_code", q._header);
            ctemplate::Template *tp = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
            tp->Expand(html, &root);
        }
    private:
    };
}